//
//  MyView.m
//  ScaleDragGrid
//
//  Created by Basuke on 08/03/26.
//  Copyright Basuke's 2008. All rights reserved.
//

#import "MyView.h"

@implementation MyView

@synthesize name;

- (void)drawRect:(CGRect)rect {
	NSLog(@"%.0f, %.0f, %.0f, %.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
	
	CGContextRef	context = UIGraphicsGetCurrentContext();
	
	CGContextSetLineWidth(context, 0.5);
	CGContextSetLineCap(context, kCGLineCapRound);
	CGContextSetStrokeColorWithColor(context, [[UIColor grayColor] cgColor]);
	
	for (CGFloat x = (rect.origin.x / 10.0); x < rect.origin.x + rect.size.width; x += 10.0) {
		CGContextSetAlpha(context, x / 500.0);
		
		CGContextBeginPath(context);
		CGContextMoveToPoint(context, x, rect.origin.y);
		CGContextAddLineToPoint(context, x, rect.origin.y + rect.size.height);
		CGContextStrokePath(context);
	}
	
	for (CGFloat y = (rect.origin.y / 10.0); y < rect.origin.y + rect.size.height; y += 10.0) {
		CGContextSetAlpha(context, y / 500.0);
		
		CGContextBeginPath(context);
		CGContextMoveToPoint(context, rect.origin.x, y);
		CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, y);
		CGContextStrokePath(context);
	}
	
	// Get the font of the appropriate size
	UIFont *font = [UIFont systemFontOfSize:14];
	
	[[UIColor whiteColor] set];
	CGPoint point = CGPointMake(4, 4);
	[self.name drawAtPoint:point forWidth:self.bounds.size.width withFont:font fontSize:14 lineBreakMode:UILineBreakModeMiddleTruncation baselineAdjustment:UIBaselineAdjustmentAlignBaselines];
}

@end
